<?php
namespace app\superadmin\controller;
use app\common\controller\SuperadminBase;
use app\superadmin\model\Admin as Model;
use think\Request;
use think\Session;
use think\Db;
class Index extends SuperadminBase{
    public function index(){

       $adminid = session('adminid');
       $info = Model::where('id',$adminid)->find();
       
       if (!$info) {
           return $this->redirect('login/index');
       }

       unset($info['pswd']);

       $this->assign('admininfo',$info);
       return $this->fetch('index/index');
		
 }


        public function statis()
    {   
    
      
        $date = date('Y-m-d');
        $starttime = $this->request->param('starttime',$date);
        $endtime = $this->request->param('endtime',$date);
        $starttime1 = $starttime." "."00:00:00";
        $endtime1 = $endtime." "."23:59:59";

        $datearr = [];

        $datearr[0] = $starttime1;
        $datearr[1] = $endtime1;

        $where['create_time'] = ['between',$datearr];



        $arr = ['南海诸岛','北京','天津','上海','重庆','河北省','河南省','云南省','辽宁省','黑龙江省','湖南省','安徽省','山东省','新疆维吾尔自治区','江苏省','浙江省','江西省','湖北省','广西壮族自治区','甘肃省','山西省','内蒙古自治区','陕西省','吉林省','福建省','贵州省','广东省','青海省','西藏自治区','四川省','宁夏回族自治区','海南省','台湾','香港特别行政区','澳门特别行政区'];


        $arr1 = ['南海诸岛','北京','天津','上海','重庆','河北','河南','云南','辽宁','黑龙江','湖南','安徽','山东','新疆','江苏','浙江','江西','湖北','广西','甘肃','山西','内蒙古','陕西','吉林','福建','贵州','广东','青海','西藏','四川','宁夏','海南','台湾','香港','澳门'];


        $ditu = [];
        for ($i=0; $i < count($arr); $i++) { 
              $ditu[$i]['name'] =  $arr1[$i];
              $ditu[$i]['value'] =  Db::table('yup_order')->where('province',$arr[$i])->where('status','>',1)->where($where)->count();
        }

        $ditu = json_encode($ditu);


        $ordernum = 0;
        $reportnum = 0;
        $deposit = 0;
        $price = 0;

        $ordernum = Db::table('yup_order')->where('status','>',1)->where($where)->count();
        $reportnum = Db::table('yup_report')->where('status',2)->where($where)->count();
        $deposit = Db::table('yup_order')->where('status','>',1)->where($where)->sum('deposit');
        $price = Db::table('yup_order')->where('status','>',1)->where($where)->sum('price');

        $this->assign('starttime',$starttime);
        $this->assign('endtime',$endtime);
        $this->assign('ordernum',$ordernum);
        $this->assign('reportnum',$reportnum);
        $this->assign('deposit',sprintf("%.2f", $deposit));
        $this->assign('price',sprintf("%.2f", $price));
        $this->assign('ditu',$ditu);
        return $this->fetch('');
    }
 


}